System media transport controls sample


Windows Runtime
Controls, Media
Windows RT
en-US
11/25/2013

This sample demonstrate how to register and handle media transport events for hardware and software buttons using the new SystemMediaTransportControls .

Windows 8.1 introduces SystemMediaTransportControls which replace MediaControl class for interacting with the system media transport controls.

Specifically, this sample shows how to:

  • Register for the play, stop, and pause buttons on the system media transport controls using the IsPlayEnabled, IsPauseEnabled, and IsStopEnabled properties.
  • Handle button presses on the system media transport controls with the ButtonPressed event. You use this event to update the status of the media playing in the app.
  • Update the status of the system media transport controls using the PlaybackStatus property. You need to update system media transport controls so they are in sync with the local media state in the app.
  • Update the media metadata that the system media transport controls displays using the SystemMediaTransportControlsDisplayUpdater. Specifically this sample shows how to use CopyFromFileAsync to automatically extract the metadata from the media file.

The system media transport controls are different than the transport controls on the XAML MediaElement object or the HTML audio and video objects. These are the controls that pop up when hardware or software media keys are pressed, such as the volume control on a pair of headphones or the media buttons on some keyboards.

For more info on the SystemMediaTransportControls, see How to use the system media transport controls.

For info on background audio, which requires handling the play and pause buttons of the system media transport controls, see How to play audio in the background.

To obtain an evaluation copy of Windows 8.1, go to Windows 8.1.

To obtain an evaluation copy of Microsoft Visual Studio 2013, go to Visual Studio 2013.

Note  For Windows 8 app samples, download the Windows 8 app samples pack. The samples in the Windows 8 app samples pack will build and run only on Microsoft Visual Studio 2012.

Related topics

SystemMediaTransportControls
SystemMediaTransportControlsDisplayUpdater
ButtonPressed
CopyFromFileAsync
How to use the system media transport controls
How to play audio in the background

Operating system requirements

Client
Windows 8.1
Server
Windows Server 2012 R2

Build the sample

  1. Start Visual Studio 2013 and select File > Open > Project/Solution.
  2. Go to the directory in which you unzipped the sample. Go to the directory named for the sample, and double-click the Visual Studio 2013 Solution (.sln) file.
  3. Press F7 or use Build > Build Solution to build the sample.

Run the sample

To debug the app and then run it, press F5 or use Debug > Start Debugging. To run the app without debugging, press Ctrl+F5 or use Debug > Start Without Debugging.